package cn.tedu.tmall.front.content.service.impl;

import cn.tedu.tmall.front.content.dao.repository.ICategoryRepository;
import cn.tedu.tmall.front.content.pojo.po.CategoryPO;
import cn.tedu.tmall.front.content.pojo.vo.CategoryItemVO;
import cn.tedu.tmall.front.content.service.ICategoryService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CategoryServiceImpl implements ICategoryService {
    @Autowired
    private ICategoryRepository categoryRepository;
    @Override
    public List<CategoryItemVO> list() {
        List<CategoryPO> categoryPOS =   categoryRepository.list();
        if(categoryPOS==null) {
            throw new RuntimeException("当前数据为空!");
        }
        List<CategoryItemVO> categoryItemVOList = new ArrayList<>();
        for (CategoryPO categoryPO : categoryPOS) {
            CategoryItemVO categoryItemVO = new CategoryItemVO();
            BeanUtils.copyProperties(categoryPO,categoryItemVO);
            categoryItemVOList.add(categoryItemVO);
        }
        return categoryItemVOList;
    }
}
